package com.three.work.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import com.three.work.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import com.three.work.bean.Post;
import com.three.work.bean.result.ResultPage;
import com.three.work.controller.model.ApiResultModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2020-04-02
 */
@Controller
@RequestMapping("/bus/post")
public class PostController extends BaseController{
     /** 主页面 */
    @RequestMapping("main.html")
    public String main(){
       return  "PostMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "/addPostHtml")
    public String addPostHtml( ){
             return "/PostAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/editPostHtml")
    public String editPostHtml(Integer id ,Model model ){
           model.addAttribute("post",postService.selectPostByIdPost(id));
             return "/PostEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/showPostHtml")
    public String showPostHtml(Integer id ,Model model ){
           model.addAttribute("post",postService.selectPostByIdPost(id));
             return "/PostShow";
    }


    /** 分页查询Post
     * @param page  页码
     * @param limit  查几条
     * @param post  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "/findPostByPage")
    @ResponseBody
    public ResultPage findPostByPage(Integer page, Integer limit,Post post){
             return postService.findPostByPage(page,limit,post);
    }

    /** 添加Post
     * @param post  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/addPost")
    @ResponseBody
    public ApiResultModel savePost(Post post  ){
             return postService.addPost(post);
    }

    /** 编辑Post
     * @param post  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/editPost")
    @ResponseBody
    public ApiResultModel editPost(Post post  ){
             return postService.editPost(post);
    }



    /** 删除一条Post
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "/delPost")
    @ResponseBody
    public ApiResultModel delPost( Integer id  ){
             return postService.delPost(id);
    }


}
